package com.muqi.app.pj.shops;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.muqi.app.im.adapter.MyFragmentPagerAdapter;

import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;

public class MineOrderListActivity extends BaseFragmentActivity implements OnClickListener {
	private TextView goodButton;
	private TextView xuniButton;
	private ViewPager orderPager;
	private MyFragmentPagerAdapter mAdapter;
	private List<Fragment> fragmentList = new ArrayList<Fragment>();
	private GoodFragment goodOrder = null;
	private GoodFragment xuniOrder = null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.aty_mine_order);

	}

	@Override
	protected void onInit() {
		goodButton = (TextView)findViewById(R.id.one2one_button);
		goodButton.setOnClickListener(this);
		xuniButton = (TextView)findViewById(R.id.class_button);
		xuniButton.setOnClickListener(this);
		orderPager = (ViewPager)findViewById(R.id.order_content);
		
	}

	@Override
	protected void onData() {
		fragmentList.clear();
		if(goodOrder == null){ 
			goodOrder = new GoodFragment(0);
		}
		if(xuniOrder == null){
			xuniOrder = new GoodFragment(1);
		}
		fragmentList.add(goodOrder);
		fragmentList.add(xuniOrder);
		if(mAdapter != null){
			mAdapter = null;
		}
		mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);
		orderPager.setAdapter(mAdapter);
		orderPager.addOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int position) {
				goodButton.setBackgroundResource(R.drawable.corners_white_10_radus);
				xuniButton.setBackgroundResource(R.drawable.corners_white_10_radus);
				goodButton.setTextColor(getResources().getColor(R.color.green));
				xuniButton.setTextColor(getResources().getColor(R.color.green));
				switch (position) {
				case 0:
					goodButton.setBackgroundResource(R.drawable.corners_grow_bg);
					goodButton.setTextColor(getResources().getColor(R.color.white));
					
					break;
				case 1:
					xuniButton.setBackgroundResource(R.drawable.corners_grow_bg);
					xuniButton.setTextColor(getResources().getColor(R.color.white));
					break;
				}
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
			}
		});
		orderPager.setCurrentItem(0);
	}

	public void finish(View view) {
		finish();
	}

	@Override
	protected void onDestroy() {

		super.onDestroy();
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.one2one_button:
			orderPager.setCurrentItem(0);
			break;
		case R.id.class_button:
			orderPager.setCurrentItem(1);
			break;
		default:
			break;
		}
		
	}

}
